{Mjagkova Jana. 12.09. min+max}
program minmax;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
min, max ,i, j: integer;
fin, fout: textFile;
mass: array of integer;

begin
  assignFile(fin, 'input.txt');
  reset(fin);
  readln(fin, n);
  setLength(mass, n+1);
  for i:= 0 to n-1 do
    begin
      read(fin, mass[i]);
    end;
  min:=mass[0];
  max:=mass[0];
  for i := 1 to n-1 do
    begin
      If mass[i]>max then
        max:==mass[i] ;
      If mass[i]<min then
        min:==mass[i];


    end;

  assignFile(fout, 'output.txt');
  rewrite(fout);

  write(fout, max+min);
   
  closeFile(fin);
  closeFile(fout);
end.
